<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人资料 - 内容评级平台</title>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --accent: #4cc9f0;
            --dark: #1d3557;
            --darker: #0d1b2a;
            --light: #f8f9fa;
            --gray: #8d99ae;
            --success: #4caf50;
            --warning: #ff9800;
            --danger: #f44336;
            --card-bg: rgba(29, 53, 87, 0.8);
            --transition: all 0.3s ease;
        }

        body {
            background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 100%);
            color: var(--light);
            min-height: 100vh;
            background-attachment: fixed;
            line-height: 1.6;
        }

        /* 主内容区样式 */
        .main-content {
            max-width: 1400px;
            margin: 2rem auto;
            padding: 0 2rem;
        }

        /* 个人管理页面样式 */
        .personal-management {
            max-width: 1200px;
            margin: 2rem auto;
            padding: 0 2rem;
        }

        /* 个人资料样式 */
        .profile-header {
            display: flex;
            align-items: center;
            margin-bottom: 2rem;
        }

        .avatar-container {
            position: relative;
            margin-right: 2rem;
        }

        .avatar-preview {
            width: 120px;
            height: 120px;
            object-fit: cover;
            border-radius: 50%;
            border: 3px solid var(--accent);
        }

        .avatar-upload {
            position: absolute;
            bottom: 0;
            right: 0;
            background: var(--primary);
            color: white;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
        }

        .profile-info {
            flex: 1;
        }

        .form-group {
            margin-bottom: 1.5rem;
        }

        .form-label {
            display: block;
            margin-bottom: 0.5rem;
            font-weight: 600;
        }

        .form-control {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid rgba(255,255,255,0.1);
            background: rgba(255,255,255,0.05);
            border-radius: 5px;
            color: var(--light);
            font-size: 1rem;
        }

        .form-control:focus {
            outline: none;
            border-color: var(--accent);
        }

        select.form-control {
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 1rem center;
            background-size: 1em;
        }

        .btn-save {
            background: var(--primary);
            color: white;
            padding: 0.8rem 1.5rem;
            border: none;
            border-radius: 5px;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
        }

        .btn-save:hover {
            background: var(--secondary);
        }

        .message {
            margin-bottom: 1rem;
            padding: 0.8rem;
            border-radius: 5px;
        }

        .error {
            background-color: rgba(244, 67, 54, 0.2);
            color: var(--danger);
        }

        .success {
            background-color: rgba(76, 175, 80, 0.2);
            color: var(--success);
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .header-container {
                flex-direction: column;
                gap: 1rem;
            }

            .nav-links {
                gap: 0.5rem;
                flex-wrap: wrap;
                justify-content: center;
            }

            .auth-buttons {
                margin-top: 1rem;
            }
        }

        @media (max-width: 768px) {
            .modal-content {
                width: 90%;
                margin: 10% auto;
            }

            .profile-header {
                flex-direction: column;
                text-align: center;
            }

            .avatar-container {
                margin-right: 0;
                margin-bottom: 1rem;
            }
        }

        @media (max-width: 480px) {
            .log-header {
                flex-direction: column;
                gap: 0.5rem;
            }

            .log-meta {
                flex-wrap: wrap;
            }

            .comment-actions,
            .log-actions {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
<%@ include file="navbar.jsp" %>
<!-- 主内容区 -->
<div class="main-content">
    <div class="personal-management">
        <h1>个人资料</h1>

        <c:if test="${not empty message}">
            <div class="message success">${message}</div>
        </c:if>
        <c:if test="${not empty error}">
            <div class="message error">${error}</div>
        </c:if>

        <form action="userProfile" method="post" enctype="multipart/form-data">
            <div class="profile-header">
                <div class="avatar-container">
                    <img src="${sessionScope.avatar != null ? sessionScope.avatar : 'images/default-avatar.jpg'}"
                         id="avatarPreview" class="avatar-preview" alt="用户头像">
                    <div class="avatar-upload" onclick="document.getElementById('avatarInput').click()">
                        <i class="fas fa-camera"></i>
                        <input type="file" id="avatarInput" name="avatar" accept="image/*" style="display: none;">
                    </div>
                </div>

                <div class="profile-info">

                    <h2>${sessionScope.user.username}</h2>
                    <p>会员ID: ${sessionScope.userId}</p>
                </div>
            </div>

            <div class="form-group">
                <label for="gender" class="form-label">性别</label>
                <select id="gender" name="gender" class="form-control">
                    <option value="male" ${sessionScope.user.gender == 'male' ? 'selected' : ''}>男</option>
                    <option value="female" ${sessionScope.user.gender == 'female' ? 'selected' : ''}>女</option>
                    <option value="other" ${sessionScope.user.gender == 'other' ? 'selected' : ''}>其他</option>
                </select>
            </div>

            <div class="form-group">
                <label for="email" class="form-label">电子邮箱</label>
                <input type="email" id="email" name="email" class="form-control"

                value="${sessionScope.user.email}" required>
            </div>

            <div class="form-group">
                <label for="phone" class="form-label">手机号码</label>
                <input type="tel" id="phone" name="phone" class="form-control"

                value="${sessionScope.user.phone}" required>
            </div>

            <div class="form-group">
                <label for="birthday" class="form-label">生日</label>
                <input type="date" id="birthday" name="birthday" class="form-control"

                value="${sessionScope.user.birthday}">
            </div>

            <div class="form-group">
                <label for="province" class="form-label">所在省份</label>
                <input type="text" id="province" name="province" class="form-control"

                value="${sessionScope.user.province}">
            </div>

            <div class="form-group">
                <label for="city" class="form-label">所在城市</label>
                <input type="text" id="city" name="city" class="form-control"

                value="${sessionScope.user.city}">
            </div>

            <button type="submit" class="btn-save">保存更改</button>
            <a href="change-password.jsp" class="btn btn-outline" style="margin-left: 1rem;">
                <i class="fas fa-key"></i> 修改密码
            </a>
        </form>
    </div>
</div>

<%@ include file="footer.jsp" %>

<script>
    // 头像预览功能
    document.getElementById('avatarInput').addEventListener('change', function(e) {
        const file = e.target.files[0];
        if (file) {
            const reader = new FileReader();
            reader.onload = function(event) {
                document.getElementById('avatarPreview').src = event.target.result;
            }
            reader.readAsDataURL(file);
        }
    });
</script>
</body>
</html>